

/*
 * 
 * 010b0a2146 - Anhänger
 * 4000e5da06 - karte 2
 * 4000e61848 - karte 1
 * 
 * 
 * 
 * 
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author evalla
 */


import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.lang.Object;
import com.phidgets.*;
import com.phidgets.event.*;
import java.awt.image.BufferedImage;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.security.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.imageio.ImageIO;

public class Batch {
    
    static MySQLConnection sql = MySQLConnection.getInstance();
    static InterfaceKitPhidget ik;
    
    static final PictureBytesHolder m_bytesHolder = new PictureBytesHolder();
    static BytesReceiver m_receiver = new BytesReceiver("172.16.1.252", "camera", "weitblick", m_bytesHolder);

    public static final void main(String args[]) throws Exception {
        RFIDPhidget rfid;
        rfid = new RFIDPhidget();
        rfid.addAttachListener(new AttachListener() {

            public void attached(AttachEvent ae) {
                try {
                    ((RFIDPhidget) ae.getSource()).setAntennaOn(true);
                    ((RFIDPhidget) ae.getSource()).setLEDOn(true);
                } catch (PhidgetException ex) {
                }
                System.out.println("attachment of " + ae);
            }
        });


        

        System.out.println(Phidget.getLibraryVersion());



        rfid.addTagGainListener(new TagGainListener() {

            public void tagGained(TagGainEvent oe) {
                System.out.println(oe);
                try {
                 
                Date now = new Date();
                SimpleDateFormat formator = new SimpleDateFormat("yyyyMMddHHmmss");
                String actdate = formator.format(now);

                PlayMusic player = new PlayMusic();
                
                
                //Foto und Timestamp Speicherung in der Datenbank
                
              /* ByteArrayInputStream stream = new ByteArrayInputStream(m_bytesHolder.getBytes());

                BufferedImage img = ImageIO.read(stream);
                String imgname = oe.getValue()+actdate+".jpg";
                File outputfile = new File("C:\\Users\\evalla\\Pictures\\test\\"+imgname);
                ImageIO.write(img, "jpg", outputfile);
                
                
                sql.insertTimeInDB(oe.getValue(),imgname,now); */
                

                
                

                } catch (Exception e) { 
                        e.printStackTrace(); 
                }
            }
        });




        rfid.addTagLossListener(new TagLossListener() {

            public void tagLost(TagLossEvent oe) {
                System.out.println(oe);

            }
        });



        rfid.openAny();
        System.out.println("waiting for RFID attachment...");
        rfid.waitForAttachment(5500);

        System.out.println("Serial: " + rfid.getSerialNumber());
        System.out.println("Outputs: " + rfid.getOutputCount());
        System.out.println("Outputting events.  Input to stop.");
        System.in.read();
        System.out.print("closing...");
        rfid.setLEDOn(false);
        rfid.close(); 
        System.out.println(" ok");
        System.exit(0x0);

    }
}
